package cn.edu.ncu.housinghub.controller;

import cn.edu.ncu.housinghub.service.impl.UserServiceImpl;
import cn.edu.ncu.housinghub.vo.Result;
import cn.edu.ncu.housinghub.constant.ErrorCodeConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 缓存管理
 */
@RestController
@RequestMapping("/cache")
public class CacheController {
    
    @Autowired
    private UserServiceImpl userService;
    
    /**
     * 清理所有用户缓存
     * @return 清理结果
     */
    @PostMapping("/clear-user-cache")
    public Result clearUserCache() {
        try {
            userService.clearAllUserCache();
            return Result.success("用户缓存清理成功");
        } catch (Exception e) {
            return Result.error(ErrorCodeConstant.SYSTEM_ERROR.getCode(), "缓存清理失败: " + e.getMessage());
        }
    }
}
